package com.housekeeping.housekeeping.administrator.adminsclassify.controller;

import com.housekeeping.housekeeping.administrator.adminsclassify.service.ClassifyService;
import com.housekeeping.housekeeping.administrator.adminsclassify.service.impl.ClassifyServiceImpl;
import com.housekeeping.housekeeping.administrator.utils.ResponseEntity;
import com.housekeeping.housekeeping.administrator.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/classify/delete")
public class DelController extends HttpServlet {
    private ClassifyService service=new ClassifyServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        int id = Integer.parseInt(req.getParameter("id"));
        ResponseEntity<Integer> entity=null;
        int count = service.delete(id);
        if (count>1){
             entity= ResponseEntity.success(count);
        }else {
           entity= ResponseEntity.error(400,"系统繁忙");
        }
        ResponseUtils.responseJson(resp,entity);
    }
}
